/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package sv.com.globalsolutionslt.convertidor;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.inject.Inject;
import sv.com.globalsolutionslt.controlador.DepartamentoFacade;
import sv.com.globalsolutionslt.entidades.Departamento;

/**
 *
 * @author karina
 */

@FacesConverter(value = "departamentoElementosConvertidor")
public class DepartamentoElementosConvertidor implements Converter{

    @Inject
    private DepartamentoFacade ejbFacade;
    
    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        return ejbFacade.encontrarPorID(Integer.parseInt(value));
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if(value == null)
            return null;
        
        Departamento d = (Departamento) value;
        return d.getIdDepartamento().toString();
        
    }
    
}
